package pl.edu.agh.mgr.hotel.ws;

import javax.jws.WebService;

import pl.edu.agh.mgr.hotel.entities.ServiceDescription;
import pl.edu.agh.mgr.hotel.ws.configuration.WSEvaluator;
import pl.edu.agh.mgr.hotel.ws.configuration.WSInitializer;
import pl.edu.agh.mgr.hotel.ws.configuration.WSUtil;
import pl.edu.agh.mgr.hotel.ws.data.DataRequest;
import pl.edu.agh.mgr.hotel.ws.data.DataResponse;

@WebService(targetNamespace = "http://ws.hotel.mgr.agh.edu.pl/", portName = "DataService13Port", serviceName = "DataService13Service")
public class DataService13 {
	private final String hotelName;
	private final String wsName;
	private final String wsAddress;

	private ServiceDescription serviceDescription;
	private WSEvaluator wsEvaluator = new WSEvaluator();
	private WSInitializer wsInitializer;

	public DataService13() {
		wsName = ((WebService)this.getClass().getAnnotation(WebService.class)).serviceName();
		wsAddress = "http://localhost:8081/HotelWS/services/"+ ((WebService)this.getClass().getAnnotation(WebService.class)).portName();
		hotelName = WSUtil.getWSName(wsAddress);
		wsInitializer = new WSInitializer(hotelName, wsName, wsAddress);
		serviceDescription = wsInitializer.initializeHotel();
	}

	public DataResponse getHotelData(DataRequest dataRequest) {
		return wsEvaluator.evalRequest(dataRequest, serviceDescription, wsName,
				wsAddress);
	}
}
